/*
 * 学科
 */

import { createAPI } from '@/utils/request'

// 学科列表
// export const subjectList = data => createAPI('/subjects', 'get', data)
export const getSubjectList = function(data) {
  const stateMapping = new Map([
    [1, '是'],
    [0, '否'],
  ])
  return createAPI('/subjects', 'get', data)
  .then(res => ({
    counts: res.data.counts,
    items: res.data.items.map((d, i) => ({
      ...d,
      addDate: d.addDate.substring(0, 19).replace('T', ' '),
      index: (data.page - 1) * data.pagesize + i + 1,
      isFrontDisplay: stateMapping.get(d.isFrontDisplay),
    })),
  }))
  .catch(err => err)
}
// 学科简单列表
export const simple = data => createAPI('/subjects/simple', 'get', data)

// 学科详情
export const getSubjectDetail = data => createAPI(`/subjects/${data.id}`, 'get', data)

// 学科添加
export const addSubject = data => createAPI('/subjects', 'post', data)

// 学科修改
export const updateSubject = data => createAPI(`/subjects/${data.id}`, 'put', data)

// 学科删除
export const removeSubject = data => createAPI(`/subjects/${data.id}`, 'delete', data)
